package com.jiapu.controller;

import com.jiapu.common.Result;
import com.jiapu.entity.Family_information;
import com.jiapu.mapper.Family_informationMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController

@RequestMapping("/family")
public class Family_informationController {

    @Resource
    Family_informationMapper family_informationMapper;

    @GetMapping("/total")
    public int getTotalCount() {
        return family_informationMapper.getTotalCount();
    }

    @GetMapping("/list")
    public Result getPeopleList(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        int offset = (currentPage - 1) * pageSize;
        return  Result.success(family_informationMapper.getFamily_information(offset, pageSize));
    }

    @GetMapping("/search")
    public Result list(@RequestParam(value="search") String family_name){
        List<Family_information> family_informationSearchList = family_informationMapper.search(family_name);
        return Result.success(family_informationSearchList);
    }

    @PostMapping
    public String addFamily_information(@RequestBody Family_information family_information){
        family_informationMapper.savef(family_information);
        return "success";
    }

    @PutMapping
    public String updateFamily_information(@RequestBody Family_information family_information){
        family_informationMapper.updateByIdf(family_information);
        return "success";
    }

    @PutMapping("/del")
    public String deleteFamily_information(@RequestBody Family_information family_information){
        family_informationMapper.deleteByIdf(family_information);
        return "success";
    }
}